<html>
<head>
  <title>Register HW change for a station</title>
  <script type ="text/javascript" src="../JavaScript/lib/jQuery/jquery.js"></script>
	<script type ="text/javascript" src="../JavaScript/lib/jQuery/jquery.jdpicker.js"></script>
	<link rel="stylesheet" href="../JavaScript/lib/jQuery/jdpicker.css" type="text/css" />
	<link rel="stylesheet" href="../JavaScript/lib/jQuery/style.css" type="text/css" />
</head>

<style type="text/css">
.jdpicker_w {
  display: inline;
}
</style>

<body>
  <?php include("../header.php"); ?>

  <div>
    <form class="searchForm" action="./ComputerDetails_AddHWComponent.php" method="get">
      Select a hardware component to be added.<br /><br />
      <input type="hidden" id="computer_id" name="computer_id" value="<?php echo $_GET['computer_id'] ?>">
      Component class:
      <select id="type" name="type">
        <option value="-1">Any type</option>
        <?php
          $id = $_GET['computer_id'];
          $con = get_connection();
          
          $result = mysql_query("call SelectAllHWComponentTypes()") or die( mysql_error() );
          while( $row = mysql_fetch_array($result) )
            {
              $sel = ($_GET['type'] == $row[0] ? 'selected="yes" ' : '');
              echo '<option value="' . $row[0] . '" ' . $sel . '>' . $row[1] . '</option>';
            }

          mysql_close($con);
        ?>
      </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      Manufactured after: <input type="text" id="manufactureDate" name="manufactureDate" class="jdpicker" value="<?php echo $_GET['manufactureDate']?>"/>
      <div style="float: right;">
        <input type="submit" value="Search"/>
      </div>
      <br /><br />
    </form>
    
    <table>
     	<tr>
			  <th>ID</th>
        <th>Install date</th>
        <th>Manufacture date</th>
        <th>Note</th>
        <th>Type</th>
        <th>Action</th>
		  </tr>
		  <?php
		    $con = get_connection();
		    
        $type = (isset($_GET['type']) ? $_GET['type'] : -1);
	      $manufactured = "'".$_GET['manufactureDate']."'";
        $query = "call SearchHWComponents(".$manufactured.", ".$type.")";

        $result = mysql_query($query, $con) or die(mysql_error());
        
        while( $row = mysql_fetch_array($result) )
        {
          echo '<tr><td>' .$row[0]. '</td><td>' .$row[1]. '</td><td>' .$row[2]. '</td><td>' .$row[3]. '</td><td>' .$row[4] .
               '</td><td><a href="./ComputerDetails.php?action=addHW&computer_id=' .$id. '&component_id=' .$row[0]. '">add to station</a></td></tr>';
        }
        
        mysql_close($con);
      ?>
    </table>
    <br />
    <div class="linkButton">
      <center><a <?php echo 'href="./ComputerDetails.php?computer_id=' .$id. '"'; ?> class="link">Cancel</a></center>
    </div>
    <br />
  </div>

</body>
</html>
